package xiaof.mapper;

import org.apache.ibatis.annotations.One;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import xiaof.domain.Order;
import xiaof.domain.User;

import java.util.List;

public interface OrderMapper {

    @Select("select * from orders where uid=#{uid}")
    public List<Order> findByUid(int uid);

    @Select("select *,o.id oid from orders o,user u where o.uid=u.id ")
    @Results({
            @Result(column = "oid",property = "id"),
            @Result(column = "ordertime",property = "ordertime"),
            @Result(column = "total",property = "total"),
            @Result(
                    property = "user",//要封装的属性名称
                    column = "uid",// 根据哪个字段去查询user表
                    javaType = User.class,//要封装的实体类型
                    one=@One(select = "xiaof.mapper.UserMapper.findById")//指定查询哪个接口的方法获得数据
            )
    })
    public List<Order> findAll();


 /*   @Select("select *,o.id oid from orders o,user u where o.uid=u.id ")
    @Results({
            @Result(column = "oid",property = "id"),
            @Result(column = "ordertime",property = "ordertime"),
            @Result(column = "total",property = "total"),
            @Result(column = "uid",property = "user.id"),
            @Result(column = "username",property = "user.username"),
            @Result(column = "password",property = "user.password")
    })
    public List<Order> findAll();
*/
}
